package com.helloniu.controller {

import com.helloniu.fl.NCHandler;
import com.helloniu.fl.SOHandler;
import com.helloniu.model.WhiteBoardModel;

public class WhiteBoardController extends AbsController {
    public function WhiteBoardController() {
        super();

        model = new WhiteBoardModel();
    }

    public static function getIns():WhiteBoardController {
        if(controller == null) {
            controller = new WhiteBoardController();
        }

        return controller;
    }

    override public function initConnection(ancHandler:NCHandler, asoHandler:SOHandler, auserID:String):void {
        if(inited) {
            return;
        }

        inited = true;
        super.initConnection(ancHandler, asoHandler, auserID);
        this.soHandler.addChangeListener(statusChange);
    }

    private function statusChange(asoHandler:SOHandler, pname:String = null,
        oldValue:* = null, newValue:* = null):void
    {
        if(pname == null) {
            return;
        }

        newValue = asoHandler.getProperty(pname);

        if(pname == "WhiteBoardData") {
            processWBChange(newValue);
        }
    }

    private function processWBChange(val:*):void {
        model.setNewObj(val);

        // update view
        updateViews();
    }

    public function sendNewObj(aobj:Object):void {
        soHandler.setProperty("WhiteBoardData", aobj);
    }



    private static var controller:WhiteBoardController;
}
}